package view.panel.play
{
	import control.panel.IPanelControl;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import global.Resource;
	
	import model.sit.SitInfoData;
	
	import utils.TextTool;
	
	import view.components.LoadingBar;
	import view.components.RemoteHtmlImg;
	import view.components.SimpleLoading;
	import view.panel.AbsPanel;
	
	public class SitInfoPanel extends AbsPanel
	{
		private var maleSign:Bitmap;
		private var femaleSign:Bitmap;
		private var headImg:RemoteHtmlImg;
		
		private var nameText:TextField;
		private var moneyText:TextField;
		private var levelText:TextField;
		private var homeText:TextField;
		private var companyText:TextField;
		private var fromText:TextField;
		
		private var container:Sprite;
		private var loading:SimpleLoading;
		
		private var expBar:LoadingBar;
		
		public function SitInfoPanel(panelControl:IPanelControl)
		{
			super(panelControl);
			resetBg(350,164);
			defaultX = 0;
			defaultY = 385;
			dropShadow();
			
			initImg();
			initText();
			initLoading();
			initExpBar();
		}
		
		private function initExpBar():void
		{
			expBar = new LoadingBar("face_expFace","face_expBg");
			expBar.x = 200;
			expBar.y = 43;
			container.addChild(expBar);
		}
		
		private function initLoading():void
		{
			loading = new SimpleLoading();
			loading.x = 150;
			loading.y = 60;
			addChild(loading);
		}
		
		private function initText():void
		{
			nameText = TextTool.getTextFieldXY(168,13,150,30,16,0xFFFFFF,"玩家姓名",false,true);
			moneyText = TextTool.getTextFieldXY(168,66,150,20,12,0xFFFFFF,"资产:");
			homeText = TextTool.getTextFieldXY(168,89,150,20,12,0xFFFFFF,"家乡:");
			companyText = TextTool.getTextFieldXY(168,112,150,20,12,0xFFFFFF,"公司:");
			fromText = TextTool.getTextFieldXY(168,135,150,20,12,0xFFFFFF,"来自:");
			levelText = TextTool.getTextFieldXY(168,40,40,20,12,0xFFFFFF,"");
			
			container.addChild(nameText);
			container.addChild(moneyText);
			container.addChild(homeText);
			container.addChild(companyText);
			container.addChild(fromText);
			container.addChild(levelText);
		}
		
		private function initImg():void
		{
			container = new Sprite();
			addChild(container);
			
			maleSign = Resource.getImgXY(316,6,"panel_male");
			container.addChild(maleSign);
			
			femaleSign = Resource.getImgXY(316,6,"panel_female");
			container.addChild(femaleSign);
			
			headImg = new RemoteHtmlImg(140,140);
			headImg.x = 11;
			headImg.y = 12;
			headImg.isLimited = false;
			container.addChild(headImg);
		}
		
		public function showLoading():void
		{
			container.visible = false;
			loading.visible = true;
			loading.start();
		}
		
		public function hideLoading():void
		{
			container.visible = true;
			loading.visible = false;
			loading.stop();
		}
		
		public function update(data:SitInfoData):void
		{
			if (data.sex == 1)
			{
				femaleSign.visible = true;
				maleSign.visible = false;
			}
			else
			{
				femaleSign.visible = false;
				maleSign.visible = true;
			}
			
			headImg.loadImg(data.bigImage);
			
			
			nameText.text = data.playerName;
			//levelText.text =
			moneyText.text = "资产:" +  data.money;
			homeText.text = "家乡:" +  data.homeTown;
			companyText.text = "公司:" +  data.company;
			fromText.text = "来自:" + data.snsName;
			levelText.text = data.level + "级";
			
			if (data.nextExp == 0)
			{
				return;
			}
			expBar.percent = data.exp / data.nextExp;
		}
	}
}